package com.qf.mapper;

import com.qf.domain.TbUser;
import com.qf.domain.UserLogin;
import com.qf.domain.UserSearch;
import org.apache.ibatis.annotations.Select;

import java.util.ArrayList;
import java.util.Set;

/**
* @author LC
* @description 针对表【tb_user】的数据库操作Mapper
* @createDate 2025-09-29 17:43:19
* @Entity .domain.TbUser
*/
public interface TbUserMapper {


    TbUser login(UserLogin user);

    int addUser(TbUser tbUser);

    TbUser getUserById(Integer id);

    int updateUserById(TbUser tbUser);

    ArrayList<TbUser> getAllUser();

    int deleteUserById(Integer id);

    int deleteUsers(ArrayList<Integer> ids);

    @Select("select * from qfdb.tb_user where username=#{username}")
    TbUser loginByUsername(String username);


    ArrayList<TbUser> getUserBySearch(UserSearch userSearch);

    @Select("SELECT DISTINCT sp.perm_tag\n" +
            "    FROM sys_user_role sur\n" +
            "    inner join sys_role_permission srp\n" +
            "    on sur.role_id = srp.role_id\n" +
            "    inner join sys_permission sp\n" +
            "    on sp.id = srp.perm_id\n" +
            "    where sur.user_id = #{id}")
    Set<String> selectByUserId(Integer id);

    @Select("select DISTINCT r.role_name from tb_user u inner join sys_user_role ur" +
            " on u.id=ur.user_id inner join sys_role r on r.id=ur.role_id where u.id=#{id}")
    Set<String> selectByUserIdV2(Integer id);
}
